﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default : KaohePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        MainLogic = new Engine(this);
        //Valiate user
        MainLogic.CheckUserSession();
        LoadNavigationControl();
        //Content control loaded depended on the navigation control
        LoadContentControl();  
    }

    //Load Navigation control 
    private void LoadNavigationControl()
    {
        //Get the navigation buttons from engine
        ArrayList NavButtons = MainLogic.GetNavigationControl();
        foreach(object o in NavButtons)
        {
            TableRow newRow = new TableRow();
            TableCell newCell = new TableCell();
            newCell.Controls.Add((LinkButton)o);
            newRow.Cells.Add(newCell);
            Table_NavButtons.Rows.Add(newRow);

        }

    }
    
    //Load content control according to current navigation button index
    private void LoadContentControl()
    {
        //Get control name from main logic
        string CtrlName = MainLogic.GetContentCtrlName();
        //load control by control name
        if (CtrlName.EndsWith(".ascx"))
        {
            Ph_Content.Controls.Add(Page.LoadControl(CtrlName));
        }
        
      
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("LoginPage.aspx");
    }
}


